//
//  SQAddressEditCell.m
//  pai
//
//  Created by pro on 14-12-2.
//  Copyright (c) 2014年 linjunjing. All rights reserved.
//

#import "SQAddressEditCell.h"

@implementation SQAddressEditCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"SQAddressEditCell" owner:self options: nil];
        if(arrayOfViews.count < 1){return nil;}
        if(![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]){
            return nil;
        }
        self = [arrayOfViews objectAtIndex:0];
    }
    return self;
}

-(void)setItem:(addr_t)address
{
    [self.editBtn setHidden:YES];
    [self.deleteBtn setHidden:YES];
    self.addressID = address.address_id;
    self.nameLabel.text = [NSString stringWithUTF8String:address.attn];
    self.mobileLabel.text = [NSString stringWithUTF8String:address.phone];
    NSMutableString* addr =[NSMutableString stringWithUTF8String:address.address];
    NSArray* arr = [addr componentsSeparatedByString:@"|"];
    if (arr.count == 1) {
        addr = arr[0];
    }else if(arr.count == 2){
        addr = [NSMutableString stringWithFormat:@"%@%@",arr[0],arr[1]];
    }
    self.addressLabel.text = [NSString stringWithFormat:@"%@%@%@",[NSString stringWithUTF8String:address.province],[NSString stringWithUTF8String:address.city],addr];
}

- (IBAction)doActionEdit:(id)sender {
    //编辑
    if (self.delegate) {
        [self.delegate addressedit:self.addressID];
    }
}

- (IBAction)doActionDelete:(id)sender {
    //删除
    if (self.delegate) {
        [self.delegate addressdelete:self.addressID];
    }
}

@end
